#ifndef PWM_OUT_H
#define PWM_OUT_H

#include <Arduino.h>
#include "pwm_api.h"

typedef enum 
{
    FREQ_NONE = -1,
    FREQ_32KHZ = 0,
    FREQ_4KHZ,
    FREQ_500HZ,
    FREQ_125HZ,
    FREQ_31HZ,
    FREQ_ANY
}PwmFreqName;


class PwmOut
{
public:
    PwmOut(PinName pin,uint8_t val=0);

    /* adjust duty cycle */
    void write (float duty_cycle=0.5);
    /* set fixed frequency mode| default duty cycle */
    void set_frequency(PwmFreqName frequency,float duty_cycle=0.5);
    /* set custom frequency mode| default duty cycle */
    void set_frequency(uint32_t freq,float duty_cycle=0.5);

    /*void period (float seconds);
    void period_ms (int ms);
    void period_us (int us);
    void period_ns (int ns);
    */
    // void test()
    // {
    //     pinMode(3, OUTPUT);

    //     OCR2A = 51;     // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz
    //     OCR2B = 26;     // defines the duty cycle - Half the OCR2A value for 50%
    //     TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);   // COM2B1 (output to OC2B) ; WGMode 7 Fast PWM (part 1)
    //     TCCR2B = _BV(WGM22)  | _BV(CS21);  
    // }
protected:
//void adjust_output_mode(WaveformGenerationMode wgm);
private:
    PinName _pin;
    uint8_t _val;
    uint8_t _timer_nx;
    PwmFreqName _fixed_freq_name;
    float _duty_cycle;
    uint32_t _any_freq;
};

#endif